/* eslint-disable no-empty-pattern */
import { api_add, api_delById, api_modifyAll, api_queryById, api_listAll } from '@/api/crud'

const pathName = 'front-route'

const state = {
  allRoute: [],
}

const mutations = {}

const actions = {
  // 添加前端路由
  add({}, objRoute) {
    return new Promise((resolve, reject) => {
      api_add(pathName, objRoute)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 删除前端路由
  delById({}, id) {
    return new Promise((resolve, reject) => {
      api_delById(pathName, id)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改前端路由
  modifyAll({}, objRoute) {
    return new Promise((resolve, reject) => {
      api_modifyAll(pathName, objRoute)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据id得到前端路由详情
  queryById({}, id) {
    return new Promise((resolve, reject) => {
      api_queryById(pathName, id)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  listAll({}) {
    return new Promise((resolve, reject) => {
      api_listAll(pathName)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
